package com.jarvis.du.baselibrary.cookie;

import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

/**
 * Author: dyj
 * Date: 2018/8/22 下午2:40
 * E-mail: duyangjun1991@163.com
 */

public class JarvisCookieJar implements CookieJar {

    private final JarvisCookieStore cookieStore;

    public JarvisCookieJar(JarvisCookieStore cookieStore) {
        this.cookieStore = cookieStore;
    }

    public JarvisCookieStore getCookieStore() {
        return this.cookieStore;
    }

    @Override
    public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
        this.cookieStore.addCookies(cookies);
    }

    @Override
    public List<Cookie> loadForRequest(HttpUrl url) {
        return this.cookieStore.getCookies();
    }
}
